const conn = require("../data");

// 男装定制产品页面渲染
module.exports.ctm_leftNav = (req, res) => {
  sanji = [12, 13, 14, 38, 39, 40, 41, 42, 43, 44, 45, 46];
  conn.query(
    "select * from pc_nav2 where href = ?;",
    [req.query.href],
    (err, data1) => {
      if (err) return console.log(err);
      if (data1[0].id == 32) {
        conn.query(
          "select * from pc_products,pc_nav2 where pc_products.nav2_id=pc_nav2.id and pc_products.father_id = 5;select count(distinct nav2_id) num from pc_products where father_id = 5;",
          [req.query.href],
          (err, data2) => {
            console.log(data2);
            res.json({
              data2,
              code: "1001"
            });
          }
        );
      } else if (data1[0].id == 5) {
        conn.query(
          "select * from pc_products,pc_nav2 where pc_products.nav2_id=pc_nav2.id and pc_products.father_id = 5 and pc_products.nav2_id != 10;select count(distinct nav2_id) num from pc_products where father_id = 5 and nav2_id != 10;",
          [req.query.href],
          (err, data2) => {
            res.json({
              data2,
              code: "1001"
            });
          }
        );
      } else if (sanji.indexOf(data1[0].id) > -1) {
        if (data1[0].none == 4) {
          conn.query(
            "select * from pc_nav2 where nav_id=?;select * from pc_products where father_id=?",
            [data1[0].id, data1[0].id],
            (req, data2) => {
              res.json({
                data2,
                code: "1002"
              });
            }
          );
        } else if (data1[0].none == 3) {
          conn.query(
            "select * from pc_nav2 where nav_id=(select nav_id from pc_nav2 where id=?);select * from pc_products where nav2_id=?",
            [data1[0].id, data1[0].id],
            (req, data2) => {
              res.json({
                data2,
                code: "1002"
              });
            }
          );
        }
      } else {
        conn.query(
          "select * from pc_products where nav2_id=?",
          data1[0].id,
          (req, data2) => {
            res.json({
              data2,
              code: "1000"
            });
          }
        );
      }
    }
  );
};
